/*UI界面*/
void add_ui();
void daybook_ui();
void table_ui(table tables[], int table_num);
/*主界面*/
void ui()
{
    customer *const head = new_customer(); /*head不可变*/
    /*初始化*/
    int i, dish_num;                     /*dish_num为菜品总数量*/
    dish full_list[N];                   /*full_list为菜单总表*/
    divided_lists lists;                 /*分好后的表*/
    dish_num = load_dish(full_list);     /*加载总表*/
    lists = divide(full_list, dish_num); /*分表*/
    table tables[100];
    int table_num = load_table(tables);
    sort_table(tables, table_num);
    ui_sign_in();
    int n = 20;
    while (n--)
    {
        getkeyboard();
    }
    fflush(stdin);
    system("cls");
    char key;
    while (1)
    {
        hideCursor();
        system("cls");
        printf("1.Table occupation\n");
        Printf("2.Order\n");
        Printf("3.Check-out\n");
        Printf("4.Dish added\n");
        Printf("5.Daily-book view\n");
        Printf("6.Unpaid customer\n");
        Printf("7.Most popular dish \n");
        fflush(stdin);
        key = getkeyboard();
        fflush(stdin);
        /*code here*/
        switch (key)
        {
        case 'E':
            myexit();
            break;
        case '1':
            table_ui(tables, table_num);
            break;
        case '2':
            print_dish(full_list, dish_num);
            system("pause");
            break;
        case '3':
            break;
        case '4':
            add_ui();
            dish_num = load_dish(full_list);     /*加载总表*/
            lists = divide(full_list, dish_num); /*分表*/
            break;
        case '5':
            daybook_ui();
            break;
        case '6':
            break;
        case '7':
            break;
        }
        Sleep(100);
    }
}
/*No.1*/
void table_ui(table tables[], int table_num)
{
    system("cls");
    int i = 0;
    printf("ID\t|Capacity\n");
    for (; i < table_num; i++)
    {
        if (tables[i].free)
        {
            printf("%s\t%d\n", tables[i].id, tables[i].capacity);
        }
        else
        {
            printf("\033[031m%s\t%d\033[0m\n", tables[i].id, tables[i].capacity);
        }
    }
    system("pause");
}
/*No.4*/
void add_ui()
{
    system("cls");
    int i = 1;
    printf("Add dishes, type in 'end' to terminate\n");
    dish adds;
    getchar();
    while (1)
    {
        printf("No%d. Name>>>", i++);
        scanf("%s", adds.name);
        if (adds.name[0] == 'e' && adds.name[1] == 'n' && adds.name[2] == 'd')
        {
            return;
        }
        printf("Type>>>");
        scanf("%s", adds.type);
        printf("Cost>>>");
        scanf("%f", &adds.cost);
        printf("Price>>>");
        scanf("%f", &adds.price);
        printf("Daily-supply>>>");
        scanf("%d", &adds.daily_supply);
        add_to_menu(adds);
    }
}
/*No.5*/
void daybook_ui()
{
    system("cls");
    FILE *f = fopen("day-book.log", "r"); /*肯定存在*/
    float price = 0, cost = 0, gt = 0, p = 0, c = 0;
    printf("Sales\t|Cost\t|Profit\n");
    printf("----------------------\n");
    while (!feof(f))
    {
        fscanf(f, "%f%f", &p, &c);
        price += p;
        cost += c;
        printf("%.1f\t%.1f\t%.1f\n", p, c, p - c);
    }
    fclose(f);
    gt = price - cost;
    printf("----------------------\n");
    printf("%.1f\t%.1f\t%.1f\n", price, cost, gt);
    char key;
    while (1)
    {
        fflush(stdin);
        key = getkeyboard();
        fflush(stdin);
        if (key == 'R' || key == ' ' || key == 'E')
        {
            return;
        }
    }
}